<template>
  <div class="web-main">
    <!--功能-->
    <el-row class="web-header">
      <el-col :span="16">
        <el-button type="primary" @click="createBtn">新增</el-button>
      </el-col>
      <el-col :span="8" style="text-align: right">
        <el-input style="width: 180px" v-model="page.condition.fleetName" @keyup.enter.native="search" placeholder="车队名称"></el-input>
        <el-button type="primary" @click="moreSearch">
          <span v-if="!searchFlag">更多</span>
          <span v-else>收起</span>
        </el-button>
      </el-col>
    </el-row>
    <!--查询条件-->
    <el-form class="web_form" :inline="true" :class="{'web_form_active': searchFlag }" label-width="140px" style="margin: 6px 0 0 0">
      <el-form-item label="车队名称">
        <el-select v-model="page.condition.fleetName" class="w184" clearable filterable remote reserve-keyword placeholder="请输入车队名"
                   :remote-method="getFleetNameList">
          <el-option v-for="(item, index) in fleetNameLists" :key="index" :label="item.fleetName" :value="item.fleetName"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否油价联动">
        <el-select v-model="page.condition.linkFlag" class="w184" clearable filterable remote reserve-keyword placeholder="请选择状态">
          <el-option key="1" label="否" value="0"></el-option>
          <el-option key="2" label="是" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="生效日期">
        <el-date-picker
          class="w184"
          v-model="page.condition.gmtCreateStart"
          type="date" clearable
          value-format = 'yyyy-MM-dd'
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item class="search-box">
        <el-button type="primary" @click="search">查询</el-button>
        <el-button type="primary" @click="resetSearch">重置</el-button>
      </el-form-item>
    </el-form>
    <!--主列表-->
    <div style="width: 100%;position: relative;">
      <el-table
        :data="tableData"
        ref="mainTable"
        header-row-class-name="table-header-center"
        border element-loading-text="正在加载中..."
        @selection-change="handleSelectionChange"
        style="margin: 0 4px;">
        <el-table-column type="selection" width="40"></el-table-column>
        <el-table-column type="index" label="序号"></el-table-column>
        <el-table-column :key="key" align="center" :width="value.width" v-for='(value,key) in tableHead'
                         :label="value.title">
          <template slot-scope="scope">
            <div v-if="value.key === 'gmtCreate'">{{scope.row.gmtCreate | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</div>
            <!--<div v-else-if="value.key === 'status'">{{scope.row.status | isFloatFilter}}</div>-->
            <div v-else>{{scope.row[value.key]}}</div>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <el-pagination
      style="margin-top: 8px"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.current"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="page.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="page.total">
    </el-pagination>
    <!-- 占位 -->
    <div style="height: 50px"></div>
  </div>
</template>

<script>
  // import * as SendByDriverLspMgt from '@/api/sendByDriverLspMgt'
  // import * as Utils from '@/utils/index'
  const defaultTableHead = [
    { key: 'fleetName', title: '车队名称', width: '120' },
    { key: 'cashPrepayRate', title: '现金预付比例', width: '100' },
    { key: 'cashFinalRate', title: '现金尾款比例', width: 100 },
    { key: 'oilPrepayRate', title: '油卡预付比例', width: '100' },
    { key: 'oilFinalRate', title: '油卡尾款比例', width: '100' },
    { key: 'gasolinePrice', title: '92#汽油价格', width: '100' },
    { key: 'dieselPrice', title: '0#柴油价格', width: '100' },
    { key: 'effectiveDate', title: '生效日期', width: '150', filter: 'parseTime("{y}-{m}-{d} {h}:{i}:{s}")' },
    { key: 'invalidDate', title: '失效日期', width: '150', filter: 'parseTime("{y}-{m}-{d} {h}:{i}:{s}")' },
    { key: 'gmtCreate', title: '创建时间', width: '150', filter: 'parseTime("{y}-{m}-{d} {h}:{i}:{s}")' }
  ]
  export default {
    name: '',
    components: { },
    data() {
      return {
        tableHead: defaultTableHead,
        searchFlag: true,
        tableData: [],
        selectRow: [],
        page: { current: 1, size: 10, total: 1,
          condition: {
            fleetName: '',
            linkFlag: '',
            priority: '',
            priceModel: '',
            gmtCreateStart: ''
          }
        },
        fleetNameLists: []
      }
    },
    created() {
      this.getList()
      this.getFleetNameList()
    },
    methods: {
      createBtn() {
        //
      },
      // 删除
      deleteBtn() {
        const that = this
        if (that.checkSelect(that.selectRow)) {
          const ids = []
          that.selectRow.map(item => {
            ids.push(item.id)
          })
          // SendByDriverLspMgt.deleteSdBaseDataInfo({ entityParams: ids }).then(result => {
          //   that.$message({
          //     message: '删除成功',
          //     type: 'success',
          //     duration: 2000
          //   })
          //   that.getList()
          // }).catch(err => {
          //   console.log('error', err)
          // })
        }
      },
      // 获取车队列表
      getFleetNameList() {
        // const that = this
        // SendByDriverLspMgt.getSdFleetList().then(res => {
        //   that.fleetNameLists = res.data
        // })
      },
      // 列表查询
      getList() {
        // const that = this
        // SendByDriverLspMgt.querySdBaseDataInfoPage(that.page).then(res => {
        //   const t = res.data
        //   that.tableData = t.records
        //   that.page.current = t.current
        //   that.page.size = t.size
        //   that.page.total = t.total
        // }).catch(err => {
        //   console.log('error', err)
        // })
      },
      // 更多
      moreSearch() {
        this.searchFlag = !this.searchFlag
      },
      // 查询
      search() {
        this.page.current = 1
        this.page.size = 10
        this.getList()
      },
      handleSizeChange(val) {
        this.page.size = val
        this.page.current = 1
        this.getList()
      },
      handleCurrentChange(val) {
        this.page.current = val
        this.getList()
      },
      // 重置
      resetSearch() {
        this.page.current = 1
        this.page.size = 10
        this.page.condition = {
        }
        this.getList()
      },
      // 检查是否选择单条
      checkSelect(data) {
        const l = data.length
        if (l === 0) {
          this.$message({
            message: '未选择',
            type: 'warning',
            duration: 2000
          })
          return false
        }
        return true
      },
      // 表格改变时
      handleSelectionChange(val) {
        this.selectRow = val
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>

</style>
